<!doctype html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{baseui/head :: head}">
    <link rel="stylesheet" href="/adminthemes/layuii/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/adminthemes/bootstrop/bootstrap/dist/css/bootstrap.css" media="all">
    <meta charset="UTF-8">
    <meta name=”viewport” content=”width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes” />
    <!-- The styles -->
    <link href="/adminthemes/area/css/bootstrap-cerulean.min.css" rel="stylesheet">

    <link href="/adminthemes/area/css/charisma-app.css" rel="stylesheet">
    <link href="/adminthemes/area/bower_components/fullcalendar/dist/fullcalendar.css" rel='stylesheet'>
    <link href="/adminthemes/area/bower_components/fullcalendar/dist/fullcalendar.print.css" rel='stylesheet'
          media='print'>
    <link href="/adminthemes/area/bower_components/chosen/chosen.min.css" rel='stylesheet'>
    <link href="/adminthemes/area/bower_components/colorbox/example3/colorbox.css" rel='stylesheet'>
    <link href="/adminthemes/area/bower_components/responsive-tables/responsive-tables.css" rel='stylesheet'>
    <link href="/adminthemes/area/bower_components/bootstrap-tour/build/css/bootstrap-tour.min.css"
          rel='stylesheet'>
    <link href="/adminthemes/area/css/jquery.noty.css" rel='stylesheet'>
    <link href="/adminthemes/area/css/noty_theme_default.css" rel='stylesheet'>
    <link href="/adminthemes/area/css/elfinder.min.css" rel='stylesheet'>
    <link href="/adminthemes/area/css/elfinder.theme.css" rel='stylesheet'>
    <link href="/adminthemes/area/css/jquery.iphone.toggle.css" rel='stylesheet'>
    <link href="/adminthemes/area/css/uploadify.css" rel='stylesheet'>
    <link href="/adminthemes/area/css/animate.min.css" rel='stylesheet'>

    <!-- jQuery -->
    <script src="/adminthemes/area/bower_components/jquery/jquery.min.js"></script>
    <title>添加供应商</title>
</head>
<style>
    h2{
        margin-left: 37%;
        font-size: 15px;
        font-weight: bold
    }
</style>
<body>
<form class="form-horizontal group-border-dashed" action="#"
      style="border-radius: 0px;">
    <h1 style="font-size: 20px;margin-left: 30%;font-weight: bold">添加保险的区域及供应商</h1>
    <h2>保险供应商</h2>
    <div class="form-group">
        <label for="supplier" class="col-sm-3 control-label">选择供应商:</label>
        <div class="col-sm-6">
        <select name="supplier" id="supplier" class="form-control" data-rel="chosen">
            <option value="0">请选择...</option>
            <#list suppliers as supplier>
                <if supplier??>
                    <option
                            value="${supplier.id}">${supplier.supplier_name}</option>
                </if>
            </#list>
        </select>
        </div>
    </div>
    <h2>分类</h2>
    <div class="form-group">
        <label  for="cat1Id" class="col-sm-3 control-label">一级分类</label>
        <div class="col-sm-6">
        <select  name="cat1Id" id="cat1Id"  class="form-control" data-rel="chosen">
                <option value="">政策性保险</option>
        </select>
        </div>
    </div>
    <div class="form-group">
        <label  for="cat2Id" class="col-sm-3 control-label">请选择二级分类</label>
        <div class="col-sm-6">
        <select  name="cat2Id" id="cat2Id"  class="form-control" data-rel="chosen">
            <#list cat2Id as cat2id>
                <option value="${cat2id.cat_id}">${cat2id.name}</option>
            </#list>
        </select>
        </div>
    </div>
    <div class="form-group">
        <label  for="cat3Id" class="col-sm-3 control-label">请选择三级分类</label>
        <div class="col-sm-6">
        <select  name="cat3Id" id="cat3Id"  class="form-control" data-rel="chosen">
            <option>选择三级分类</option>
        </select>
        </div>
    </div>
    <h2>基本信息</h2>
    <div class="form-group">
        <label class="col-sm-3 control-label" >保险名称</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入保险名称" id="insurancename"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >保险编号</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入保险编号" id="sn"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >单位保险金额 </label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入单位保险金额 " id="unit_money"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >市场价格</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入市场价格" id="mtkprice"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >最高保障金额</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入最高保障金额" id="max_money"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" for="status">是否上架</label>
        <div class="col-sm-6" style="width: 150px">
            <select class="form-control" name="devicetype" id="status">
                <option value="1">是</option>
                <option value="0">否</option>
            </select>
        </div>
    </div>
    <div style="text-align: center" class="layui-upload">
        <div class="layui-upload-list">
            <img class="layui-upload-img" style="width:100px;height:100px;" id="pic1">
            <p id="demoText"></p>
            <!--<img class="layui-upload-img" src="" style="width:100px;height:100px;display: none" id="pic">-->
            <input id="pic" name="pic" type="hidden"/>
        </div>
        <button type="button" class="btn btn-primary" id="test1">
            上传保险图片
        </button>
    </div>

    <h2>保险补贴</h2>
    <div class="form-group">
        <label class="col-sm-3 control-label" >保险标的</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入保险标的" id="item"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >单位</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入单位" id="unit"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >保险费率(%)</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入保险费率(%)" id="insured_subsidies"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >中央财政补贴比例(%)</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入中央财政补贴比例(%)" id="central_subsidies"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >省财政补贴比例(%)</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入省财政补贴比例(%)" id="province_subsidies"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >地方（市）补贴比例(%)</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入地方（市）补贴比例(%)" id="city_subsidies"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >县区补贴费率比例(%)</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="县区补贴费率比例(%)" id="region_subsidies"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >农户费率比例(%)</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入农户费率比例(%)" id="farmer_subsidies"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >其他费率比例(%)</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入其他费率比例(%)" id="other_subsidies"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >投保人申明</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入投保人申明" id="insurance_accountfor"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label" >险种说明</label>
        <div class="col-sm-6">
            <input type="text" class="form-control"
                   placeholder="请输入险种说明" id="descprtion"/>
        </div>
    </div>
    <h2>保险投放区域</h2>
        <div class="form-group">
            <label  class="col-sm-3 control-label">请选择省份</label>
            <div class="col-sm-6">
                <select  name="province" id="provinceId"  class="form-control" data-rel="chosen">
                    <#list provinceList as province>
                        <option value="${province.area_code}">${province.area_name}</option>
                    </#list>
                </select>
            </div>
        </div>
        <div class="form-group" >
            <label for="cityId" class="col-sm-3 control-label">选择城市:</label>
            <div class="col-sm-6">
            <select  name="city" id="cityId"  class="form-control" data-rel="chosen">
                <option>选择城市</option>
            </select>
            </div>
        </div>
        <div class="form-group">
            <label for="areaId" class="col-sm-3 control-label">选择区域:</label>
            <div class="col-sm-6">
            <select name="area" id="areaId"  class="form-control" data-rel="chosen" >
                <option>选择区域</option>
            </select>
            </div>
        </div>

        <!--<div class="form-group" style=" margin-left:20%;margin-right: 30%">-->
            <!--<label for="good">选择政策性保险:</label>-->
            <!--<select data-placeholder="政策性保险" name="good" id="good" class="form-control" data-rel="chosen">-->
                <!--<option value="0">请选择...</option>-->
                <!--<#list goods as good>-->
                    <!--<if good??>-->
                        <!--<option-->
                                <!--value="${good.goods_id}">${good.name}</option>-->
                    <!--</if>-->
                <!--</#list>-->
            <!--</select>-->
        <!--</div>-->

        <div class="form-actions">
            <button style="margin-left:40%" type="button" class="btn btn-primary"
                    onclick="saveInsuranceArea()">
                保存
            </button>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <button class="btn" type="reset" onclick="repic()">重写</button>
            &nbsp;&nbsp;&nbsp;&nbsp;
            <button style="margin-left:5%" class="btn" type="button" onclick="history.back()">返回
            </button>

        </div>
    </form>


<!--/row-->
</body>
<script type="text/javascript" src="/adminthemes/layuii/layui/layui.js"></script>
<script >
    /*页面加载就开始执行*/

        $("#provinceId").change(function () {
            var id = $("#provinceId").val();
            var postData = {id: id,};
            $.ajax({
                type: "Get",
                url: "/web/sysarea/getSysCityByProvinceId.do",
                data: postData,
                dataType: "json",
                success: function (data) {
                    if (data.status) {
                        var result = "<option>选择城市</option>";
                        $.each(data.obj, function (n, value) {
                            result += "<option value='" + value.area_code + "'>" + value.area_name + "</option>";
                        });
                        $("#cityId").html('');
                        $("#cityId").append(result);
                    }
                }
            })
        });
        $("#cityId").change(function () {
            //alert("111");
            var id = $("#cityId").val();
            var postData = {id: id};
            $.ajax({
                type: "Get",
                url: "/web/sysarea/getSysAreaByCityId.do",
                data: postData,
                dataType: "json",
                success: function (data) {
                    if (data.status) {
                        var result = "<option>选择区域</option>";
                        $.each(data.obj, function (n, value) {
                            result += "<option value='" + value.area_code + "'>" + value.area_name + "</option>";
                        });
                        $("#areaId").html('');
                        $("#areaId").append(result);
                    }
                }
            })
        });
        $("#cat2Id").change(function () {
            var id = $("#cat2Id ").val();
            var postData = {id: id};
            $.ajax({
                type: "Get",
                url: "/web/sysarea/getCat3ByCat2.do",
                data: postData,
                dataType: "json",
                success: function (data) {
                    if (data.status) {
                        var result = "<option>选择三级分类</option>";
                        $.each(data.obj, function (n, value) {
                            result += "<option value='" + value.cat_id + "'>" + value.name + "</option>";
                        });
                        $("#StreetId").html('');
                        $("#StreetId").append(result);
                    }
                }
            })
        });

        layui.use('upload', function () {
            var $ = layui.jquery
                , upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                , url: '/admin/insurancecom/upload/companylogo1.do'
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result) {
                        $('#pic1').attr('src', result); //图片链接（base64）
                    });
                }
                , done: function (res) {
//                layer.alert(res);
//                alert(res);
//                console.info(res);
                    if (res.success) {
//                    $('#pic').attr('src', res.result);
                        $("#pic").val(res.result);
                        return layer.alert('上传成功！');
                        ;
                    }
                }
            })
        });

        function saveInsuranceArea() {
            layui.use('layer', function () {
                var $ = layui.jquery, layer = layui.layer;
                var cat3Id = $("#cat3Id").val();
                var insurancename = $("#insurancename").val();
                var sn = $("#sn").val();
                var unit_money = $("#unit_money").val();
                var mtkprice = $("#mtkprice").val();
                var max_money = $("#max_money").val();
                var status = $("#status").val();
                var pic = $("#pic").val();
                var item = $("#item").val();
                var unit = $("#unit").val();
                var insured_subsidies = $("#insured_subsidies").val();
                var central_subsidies = $("#central_subsidies").val();
                var province_subsidies = $("#province_subsidies").val();
                var city_subsidies = $("#city_subsidies").val();
                var region_subsidies = $("#region_subsidies").val();
                var other_subsidies = $("#other_subsidies").val();
                var insurance_accountfor = $("#insurance_accountfor").val();
                var descprtion = $("#descprtion").val();
                var provinceId = $("#provinceId").val();
                var cityId = $("#cityId").val();
                var areaId = $("#areaId").val();
                var supplier = $("#supplier").val();
                var postData = {
                    provinceId: provinceId,
                    cityId: cityId,
                    areaId: areaId,
                    cat3Id:cat3Id,
                    insurancename:insurancename,
                    sn:sn,
                    unit_money:unit_money,
                    mtkprice:mtkprice,
                    max_money:max_money,
                    status:status,
                    pic:pic,
                    item:item,
                    unit:unit,
                    insured_subsidies:insured_subsidies,
                    central_subsidies:central_subsidies,
                    province_subsidies:province_subsidies,
                    city_subsidies:city_subsidies,
                    region_subsidies:region_subsidies,
                    other_subsidies:other_subsidies,
                    insurance_accountfor:insurance_accountfor,
                    descprtion:descprtion,
                    supplier: supplier
                }
                $.ajax({
                    type: "POST",
                    url: "/web/sysarea/addgood.do",
                    data: postData,
                    dataType: "json",
                    success: function (data) {
                        if (data = true) {
                            layer.open({
                                content: '添加完成，请返回'
                                , yes: function (index, layero) {
                                    location.href = '/shop/admin/goods/list.do';
                                }
                                , cancel: function () {
                                    return false;// 开启该代码可禁止点击该按钮关闭
                                }
                            });
                        }
                        else {
                            layer.alert('添加失败，请重试！');
                        }
                    }
                })
            });
        };




</script>
</html>